#include <iostream>
#include <vector>
using namespace std;

class Solution {
    public:
	int majorityElement(vector<int> &nums)
	{
		int cond = 0, hp = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (hp == 0) {
				cond = nums[i];
                                hp = 1;
			} else {
				if (cond == nums[i]) {
					hp++;
				} else {
					hp--;
				}
			}
		}
		if (hp == 0) {
			return -1;
		}

		hp = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] == cond) {
				hp++;
			}
		}

		return hp > nums.size() / 2 ? cond : -1;
	}
};

int main()
{
	vector<int> nums = { 3, 2, 3 };
	cout << Solution().majorityElement(nums) << endl;
	return 0;
}